package tool

import (
	"math"
	"parkour/model"
)

func IsCollision(object1, object2 *model.Entity) bool {
	if math.Abs(object2.X+float64(object2.Width/2)-object1.X-float64(object1.Width)/2) < math.Abs(float64(object2.Width+object1.Width)/2) &&
		math.Abs(object2.Y+float64(object2.Height)/2-object1.Y-float64(object1.Height)/2) < math.Abs(float64(object2.Height+object1.Height)/2) {
		return true
	}
	return false
}

func IsCollision2(object1, object2 *model.Entity) bool {
	left1 := object1.X
	right1 := object1.X + float64(object1.Width/2)
	top1 := object1.Y
	bottom1 := object1.Y + float64(object1.Height/2)

	left2 := object2.X
	right2 := object2.X + float64(object2.Width/2)
	top2 := object2.Y
	bottom2 := object2.Y + float64(object2.Height/2)

	if left1 < right2 && right1 > left2 && top1 < bottom2 && bottom1 > top2 {
		return true
	}

	return false
}
